<template>
	<transition name="acf-opts">
		<div v-show="optsStore.visible" class="acf-opts">
			<div class="acf-opts-header">
				<h2>设置</h2>
				<UIIcon icon="close" :size="16" @click="close"></UIIcon>
			</div>
			
			<div class="acf-opts-aside">
				<el-menu
					:default-active="optsStore.menuActive"
					@select="selectMenu">
					<el-menu-item v-for="item in optsStore.menuItems" :key="item.index" :index="item.index">{{item.title}}</el-menu-item>
				</el-menu>
			</div>
			
			<div class="acf-opts-main">
				<transition name="acf-opts-main-comp" mode="out-in">
					<keep-alive>
						<CompPlayerConfig v-if="optsStore.menuActive === 'player'" />
						<CompFeedback v-else-if="optsStore.menuActive === 'feedback'" />
						<CompSound v-else-if="optsStore.menuActive === 'sound'" />
					</keep-alive>
				</transition>
			</div>
		</div>
	</transition>
</template>

<script setup>
	
	import { ref, reactive, watch, computed } from 'vue';
	import UIIcon from '@/ui/icon';
	import CompPlayerConfig from './CompPlayerConfig';
	import CompFeedback from './CompFeedback';
	import CompSound from './CompSound';
	import useOptsStore from './useOptsStore';
	import useSoundStore from './useSoundStore';
	
	const optsStore = useOptsStore();
	const soundStore = useSoundStore();
	
	watch(() => optsStore.visible, () => {
		soundStore.clearAllSound();
	})
	
	function close() {
		optsStore.visible = false;
	}
	
	function selectMenu(key) {
		optsStore.menuActive = key;
	}
	
</script>

<style lang="scss" scoped>
	
	@import './mixin.scss';
	@import '@/theme/material/media.scss';
	
	.acf-opts {
		@include acfFullOverlayer;
		z-index: 5;
		display: grid;
		gap: 24px;
		place-items: stretch;
		place-content: stretch;
		grid-template-columns: 1fr;
		grid-template-rows: auto 100px 4fr;
		grid-template-areas: 
			'header'
			'aside'
			'main';
		@include mediaMd {
			grid-template-columns: 160px 1fr;
			grid-template-rows: auto 1fr;
			grid-template-areas: 
				'header header'
				'aside main';
		}
	}
	
	.acf-opts-enter-from,
	.acf-opts-leave-to {
		opacity: 0;
	}
	
	.acf-opts-header {
		grid-area: header;
		display: flex;
		align-items: center;
		justify-content: space-between;
		:deep(.ui-icon) {
			cursor: pointer;
		}
	}
	
	.acf-opts-aside {
		grid-area: aside;
		overflow: hidden auto;
		:deep(.el-menu) {
			height: 100%;
			--el-menu-bg-color: tranparent;
			--el-menu-hover-bg-color: rgba(255, 255, 255, .5);
			--el-menu-text-color: #fff;
		}
	}
	
	.acf-opts-main {
		grid-area: main;
		overflow: hidden auto;
		padding: 10px 24px 10px 12px;
	}
	
	.acf-opts-main-comp-enter-active {
		transition: .25s ease-in;
	}
	.acf-opts-main-comp-leave-active {
		transition: .25s ease-out;
	}
	
	.acf-opts-main-comp-enter-from {
		transform: translateX(-20px);
		opacity: 0;
	}
	
	.acf-opts-main-comp-leave-to {
		transform: translateX(20px);
		opacity: 0;
	}
	
</style>